<?php

require_once __DIR__ . '/../inc/App.php';
require_once __DIR__ . '/../sparql/SparqlClient.php';

$app = new App("Test");
//$db = $app->getDb();

$client = new SparqlClient;

$query = "naissance Omar+Sy";

$keywords = explode(' ', $query);
$labelFilters = array_map(function($label)
{
    return 'fn:contains(?label, "'.str_replace('+', ' ', $label).'"@fr)';
}, $keywords);

var_dump('FILTER('.(implode(' || o', $labelFilters)).')'); die();
$results = $client->query('SELECT DISTINCT * {
   ?s ?p ?o.
   ?s rdfs:label ?label
   FILTER('.(implode('||', $labelFilters)).')
}
LIMIT 20
');

$json = array_map(function(SparqlResult $result)
{
    return array("s" => $result->getSubject(), "p" => $result->getProperty(), "o" => $result->getObject());
}, $results);

header('Content-Type: application/json');
echo json_encode($json);